package com.path.algorithms;


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;



public class AdjacencyMatrix {
	private ArrayList< ArrayList<Integer> > am;
	
	public ArrayList< ArrayList<Integer> > getAdjacencyMatrix(){
		return this.am;
	}
	
	public AdjacencyMatrix(){
		this.am = new ArrayList<ArrayList<Integer>>();
	}
	
	
	public void printMatrix(){
		Iterator<ArrayList<Integer> > it = this.am.iterator();
		while(it.hasNext()){
			this.printRow(it.next());
		}
	}
	
	public void printRow(ArrayList<Integer> row){
		Iterator<Integer> it = row.iterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();
	}
	
	public void createMatrixFromFile(String fileName) throws IOException{
		FileInputStream fstream = new FileInputStream(fileName);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String line;
		while((line = br.readLine()) != null){
			stringToRow(line);
		}
		
		in.close();
	}
	
	private void stringToRow(String line){
		StringTokenizer st = new StringTokenizer(line);
		ArrayList<Integer> row = new ArrayList<Integer>();
		while(st.hasMoreTokens()){
			int i = Integer.parseInt(st.nextToken());
			row.add(i);
		}
		this.am.add(row);
	}
	
	public ArrayList<Integer> getVertex(int n){
		return this.am.get(n);
	}
}
